<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateCategoryStatisticsAPIRequest;
use App\Http\Requests\API\UpdateCategoryStatisticsAPIRequest;
use App\Models\CategoryStatistics;
use App\Repositories\CategoryStatisticsRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class CategoryStatisticsController
 * @package App\Http\Controllers\API
 */

class CategoryStatisticsAPIController extends AppBaseController
{
    /** @var  CategoryStatisticsRepository */
    private $categoryStatisticsRepository;

    public function __construct(CategoryStatisticsRepository $categoryStatisticsRepo)
    {
        $this->categoryStatisticsRepository = $categoryStatisticsRepo;
    }

    /**
     * Display a listing of the CategoryStatistics.
     * GET|HEAD /categoryStatistics
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->categoryStatisticsRepository->pushCriteria(new RequestCriteria($request));
        $this->categoryStatisticsRepository->pushCriteria(new LimitOffsetCriteria($request));
        $categoryStatistics = $this->categoryStatisticsRepository->all();

        return $this->sendResponse($categoryStatistics->toArray(), 'Category Statistics retrieved successfully');
    }

    /**
     * Store a newly created CategoryStatistics in storage.
     * POST /categoryStatistics
     *
     * @param CreateCategoryStatisticsAPIRequest $request
     *
     * @return Response
     */
    public function store(CreateCategoryStatisticsAPIRequest $request)
    {
        $input = $request->all();

        $categoryStatistics = $this->categoryStatisticsRepository->create($input);

        return $this->sendResponse($categoryStatistics->toArray(), 'Category Statistics saved successfully');
    }

    /**
     * Display the specified CategoryStatistics.
     * GET|HEAD /categoryStatistics/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        /** @var CategoryStatistics $categoryStatistics */
        $categoryStatistics = $this->categoryStatisticsRepository->findWithoutFail($id);

        if (empty($categoryStatistics)) {
            return $this->sendError('Category Statistics not found');
        }

        return $this->sendResponse($categoryStatistics->toArray(), 'Category Statistics retrieved successfully');
    }

    /**
     * Update the specified CategoryStatistics in storage.
     * PUT/PATCH /categoryStatistics/{id}
     *
     * @param  int $id
     * @param UpdateCategoryStatisticsAPIRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateCategoryStatisticsAPIRequest $request)
    {
        $input = $request->all();

        /** @var CategoryStatistics $categoryStatistics */
        $categoryStatistics = $this->categoryStatisticsRepository->findWithoutFail($id);

        if (empty($categoryStatistics)) {
            return $this->sendError('Category Statistics not found');
        }

        $categoryStatistics = $this->categoryStatisticsRepository->update($input, $id);

        return $this->sendResponse($categoryStatistics->toArray(), 'CategoryStatistics updated successfully');
    }

    /**
     * Remove the specified CategoryStatistics from storage.
     * DELETE /categoryStatistics/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        /** @var CategoryStatistics $categoryStatistics */
        $categoryStatistics = $this->categoryStatisticsRepository->findWithoutFail($id);

        if (empty($categoryStatistics)) {
            return $this->sendError('Category Statistics not found');
        }

        $categoryStatistics->delete();

        return $this->sendResponse($id, 'Category Statistics deleted successfully');
    }
}
